package com.weizai.carshop.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weizai.carshop.common.enumeration.AppHttpCodeEnum;
import com.weizai.carshop.common.result.PageResult;
import com.weizai.carshop.common.result.ResponseResult;
import com.weizai.carshop.model.dto.QueryGoodsInfoDto;
import com.weizai.carshop.model.entiity.GoodsInfoEntity;
import com.weizai.carshop.service.GoodsInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/user/goodsInfo")
@RequiredArgsConstructor
public class GoodsInfoController {

    private final GoodsInfoService goodsInfoService;

    /*
     * 查询商品信息
     * */
    @GetMapping
    public ResponseResult queryGoodsInfo(QueryGoodsInfoDto dto) {
        Page<GoodsInfoEntity> page = goodsInfoService.lambdaQuery()
                .eq(dto.getCateId() != null, GoodsInfoEntity::getCateId, dto.getCateId())
                .page(new Page<>(dto.getPage(), dto.getPageSize()));

        return ResponseResult.okResult(new PageResult(page.getTotal(),page.getRecords()));
    }
}
